const App = {
  mixins: [Save], //配置文件，路径/utils/mixins.js
  data() {
    return {
      category: [],
      depart: [],
    };
  },
  mounted() {
    this.a();
    this.Init();
  },
  watch: {},
  methods: {
    a() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryForObtainingTrees`,
        type: "GET",
        data: {
          TableName: "complaints_categories",
        },
        success: (data) => {
          console.log(data);
          _this.category = _this.convertToCascaderFormat(data);
          console.log(_this.category);
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    convertToCascaderFormat(items) {
      const _this = this;
      console.log(items);
      return items.map((item) => ({
        label: item.category_name,
        value: item.category_id,
        // 递归处理子节点
        children: item.children
          ? _this.convertToCascaderFormat(item.children)
          : [],
      }));
    },
    convert(items) {
      const _this = this;
      console.log(items);
      return items.map((item) => ({
        label: item.Agensies_Name,
        value: item.Government_Agencies_SerialNumber,
        // 递归处理子节点
        children: item.children ? _this.convert(item.children) : [],
      }));
    },
    Init() {
      const _this = this;
      //归属部门
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryForObtainingTrees`,
        type: "get",
        data: {
          TableName: "government_agencies",
        },
        success: (data) => {
          console.log(data);

          _this.depart = _this.convert(data); // 直接使用 this
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });

      //类别
      //   $.ajax({
      //     headers: requestHeaders(),
      //     url: `${mh}/generalBusiness/generalQueryByTableName`,
      //     type: "POST",
      //     data: {
      //       Data: "complaints_categories",
      //       Condition: "Row_Status='0'",
      //     },
      //     success: (data) => {
      //       this.category = data; // 直接使用 this
      //     },
      //     complete: (XMLHttpRequest) => {
      //       requestPretreatment(XMLHttpRequest);
      //     },
      //     dataType: "json",
      //   });
    },
  },
};
const { createApp, ref } = Vue;
const app = createApp(App);
app.use(ElementPlus, { locale: zhCn });
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
app.component("yl-upload", ylUpload);
app.component("yl-text-editor", ylTextEditor);
const ElMessage = ElementPlus.ElMessage;
app.mount("#app");
